<template>
  <div>
    <input
      type="text"
      v-model="username"
      placeholder="用户名"
    >
    <input
      type="text"
      v-model="password"
      placeholder="密码"
    >
    <button @click="login">登录</button>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login() {
      var data = {
        username: this.username,
        password: this.password,
      }
      axios.post('/login/', data).then((resp) => {
        console.log(resp.data)
        localStorage.token = resp.data.token
        localStorage.uid = resp.data.uid
        localStorage.username = resp.data.username
        localStorage.email = resp.data.email
        localStorage.role = resp.data.role
        location.href = '/'
      })
    }
  }
}
</script>

<style>
</style>